<template>
  <div>
    给定固定大小的父
    子盒子，要实现子盒子上下左右居中，你有几种方法？（css完整代码截图）
  </div>
  <br />
  <!-- <div class="parent_1">
    <div class="child_1">方法一：绝对定位position + transform</div>
  </div> -->
  <!-- <div class="parent_2">
    <div class="child_2">方法二：Flexbox布局</div>
  </div> -->
  <div class="parent_3">
    <div class="help_3">
      <div class="child_3">方法三：table-cell</div>
    </div>
  </div>
  <!-- <div class="parent_4">
    <div class="child_4">方法四：CSS Grid</div>
  </div> -->
</template>

<script setup lang="ts"></script>

<style lang="scss" scoped>
//第一种 绝对定位position + transform
.parent_1 {
  position: relative;
  width: 200px;
  height: 200px;
  background: #f0f0f0;

  .child_1 {
    position: absolute;
    width: 100px;
    height: 100px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #c66;
  }
}
// 方法二：Flexbox布局
.parent_2 {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 200px;
  height: 200px;
  background: #f0f0f0;
  .child_2 {
    width: 100px;
    height: 100px;
    background: #6c6;
  }
}
// 方法三：table-cell
.parent_3 {
  width: 200px;
  height: 200px;
  background: #f0f0f0;
  display: table-cell;
  vertical-align: middle;
  .child_3 {
    width: 100px;
    height: 100px;
    background: rgba(31, 175, 180, 0.521);
    margin: auto;
  }
}
// 方法四：CSS Grid
.parent_4 {
  display: grid;
  place-items: center; /* 同时做水平和垂直居中 */
  width: 200px;
  height: 200px;
  background: #f0f0f0;
  .child_4 {
    width: 100px;
    height: 100px;
    background: #66c;
  }
}
</style>
